package com.ymatou.iapi.trading.sellerquery2.parameter.sp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ymttest.database.model.YmtTradingItem;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtCreditDetailWapper;
import com.ymttest.database.sqlwapper.YmtOOrderNoteWapper;
import com.ymttest.database.sqlwapper.YmtOrderExtWapper;
import com.ymttest.database.sqlwapper.YmtOrdersWapper;
import com.ymttest.database.sqlwapper.YmtTradingItemWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.YMTDateUtil;

/**
 * 存储过程：sp_trd_GetSellerOrdersByOrderIds_v1
 * 
 * @author songyefeng
 *
 */
@SuppressWarnings("rawtypes")
public class Sp_GetSellerOrdersByOrderIds_v1 {
	private List<Integer> orderdt;
	private Integer sellerId;
	private int totalCount;

	public List<Integer> getOrderdt() {
		return orderdt;
	}

	public void setOrderdt(List<Integer> orderdt) {
		this.orderdt = orderdt;
	}

	public Integer getSellerId() {
		return sellerId;
	}

	public void setSellerId(Integer sellerId) {
		this.sellerId = sellerId;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	private class OrderToBill {
		private int iOrderId;
		private String sBillId;

		public OrderToBill(int iOrderId, String sBillId) {
			this.iOrderId = iOrderId;
			this.sBillId = sBillId;
		}

		public OrderToBill() {

		}

		public int getiOrderId() {
			return iOrderId;
		}

		public void setiOrderId(int iOrderId) {
			this.iOrderId = iOrderId;
		}

		public String getsBillId() {
			return sBillId;
		}

		public void setsBillId(String sBillId) {
			this.sBillId = sBillId;
		}

	}

	public static class OrderTradingId {
		private int iOrderId;
		private int iTradingId;
		private String virtualTime;

		public OrderTradingId() {
		}

		public OrderTradingId(int iOrderId, int iTradingId, String virtualTime) {
			this.iOrderId = iOrderId;
			this.iTradingId = iTradingId;
			this.virtualTime = virtualTime;
		}

		public int getiOrderId() {
			return iOrderId;
		}

		public void setiOrderId(int iOrderId) {
			this.iOrderId = iOrderId;
		}

		public int getiTradingId() {
			return iTradingId;
		}

		public void setiTradingId(int iTradingId) {
			this.iTradingId = iTradingId;
		}

		public String getVirtualTime() {
			return virtualTime;
		}

		public void setVirtualTime(String virtualTime) {
			this.virtualTime = virtualTime;
		}

	}

	// public Sp_GetSellerOrdersByOrderIds_v1 execute() {
	// YmtOrdersWapper ymtOrdersWapper = new YmtOrdersWapper();
	//
	// List<Integer> orderIds = new ArrayList<Integer>();
	// List<OrderToBill> orderToBills = new
	// ArrayList<Sp_GetSellerOrdersByOrderIds_v1.OrderToBill>();
	// List<OrderTradingId> orderTradingIds = new
	// ArrayList<Sp_GetSellerOrdersByOrderIds_v1.OrderTradingId>();
	// int rowsCount = 0;
	//
	// if (DataUtil.isNullOrEmpty(orderdt) == false) {
	// orderIds.addAll(orderdt);
	// }
	//
	// // 统计当前页订单数量
	// rowsCount = orderIds.size();
	//
	// // 统计订单总量
	// // totalCount = TotalCount;
	//
	// // 当页订单的详细信息
	// String queryField = " o.*, [RealPay].*, [OrderNote].*";
	// String joinCondition = " outer apply (";
	// joinCondition +=
	// " select [RealSettlementAmountOfCoupon] = sum(t3.[SettlementAmountOfCoupon]),";
	// joinCondition += " [TotalSalesRefundAmount] = sum(t3.[RefundAmount]),";
	// joinCondition +=
	// " [totalRefundThirdPartyDiscount] = sum(isnull(t3.RefundedDiscountOfThirdParty,0))";
	// joinCondition +=
	// " from [dbo].[Ymt_RefundBill] as t3 with(nolock) where t3.[OrderId] in "
	// + DataUtil.toInOfSql(orderIds)+" and t3.[SalesRefundStatus] = 10";
	// joinCondition += " ) as [RealPay]";
	// joinCondition += " outer apply (";
	// joinCondition +=
	// " select top 1 [note].[iRemarkLevel] , [RemarkContent] = [note].[sContent]";
	// joinCondition += " from [dbo].[Ymt_O_OrderNote] as [note] with(nolock) ";
	// joinCondition +=
	// " where [note].[iOrderId] = o.[iOrderId] and [note].[iUserId] = o.[iBuyerId]";
	// joinCondition += " ) as [OrderNote]";
	// String queryCondition = " o.iOrderId in "
	// + DataUtil.toInOfSql(orderIds);
	// queryCondition +=
	// " order by o.iMainOrderId desc ,o.iOrderId asc, o.sYmtCouponCode desc option(recompile);";
	// OrderList = ymtOrdersWapper.selectOrders2(queryField, joinCondition,
	// queryCondition);
	// String sql ="select t2.* ,"
	// +"	[RealPay].* ,"
	// +"	[OrderNote].*"
	// +" from [dbo].[Ymt_Orders] as t2 with(nolock)"
	// +" outer apply ("
	// +"	select"
	// +"		[RealSettlementAmountOfCoupon] = sum(t3.[SettlementAmountOfCoupon]),"
	// +"		[TotalSalesRefundAmount] = sum(t3.[RefundAmount]),"
	// +"		[TotalRefundThirdPartyDiscount] = sum(isnull(t3.RefundedDiscountOfThirdParty,0))"
	// +"	from [dbo].[Ymt_RefundBill] as t3 with(nolock) where t3.[OrderId] in"
	// + DataUtil.toInOfSql(orderIds)+" AND t3.[SalesRefundStatus] = 10"
	// +" ) as [RealPay]"
	// +" outer apply ("
	// +"	select top 1 [note].[iRemarkLevel] , [RemarkContent] = [note].[sContent]"
	// +"	from [dbo].[Ymt_O_OrderNote] as [note] with(nolock) "
	// +"	where [note].[iOrderId] = t2.[iOrderId] and [note].[iUserId] = t2.[iBuyerId]"
	// +") as [OrderNote]"
	// +"  where [t2].[iOrderId] in" + DataUtil.toInOfSql(orderIds)
	// +" order by t2.[iMainOrderId] desc ,t2.[iOrderId] asc, [t2].[sYmtCouponCode] desc option(recompile)";
	// OrderList = new DefaultWapper().executeSql(sql);
	//
	// // 获取评价列表
	// YmtCreditDetailWapper ymtCreditDetailWapper = new
	// YmtCreditDetailWapper();
	// CreditDetailList = ymtCreditDetailWapper.selectCreditDetail(" * ",
	// null, " sTargetId in " + DataUtil.toInOfSql(orderIds));
	//
	// // 获取备注列表
	// if (rowsCount > 0) {
	// YmtOOrderNoteWapper ymtOOrderNoteWapper = new YmtOOrderNoteWapper();
	// OrderNoteList = ymtOOrderNoteWapper.selectOrderNotes(
	// " [iOrderId], [sContent] , [iRemarkLevel] ",
	// null,
	// " iUserId = " + sellerId + " and iOrderId in "
	// + DataUtil.toInOfSql(orderIds));
	// }
	// // 获取订单金额详情列表
	// DefaultWapper defaultWapper = new DefaultWapper();
	// if (rowsCount > 0) {
	// OrderStateList = defaultWapper.selectOrderStatesByOrderIds(" * ",
	// null, " iOrderId in " + DataUtil.toInOfSql(orderIds));
	// }
	// // 获取订单补款列表
	// if (rowsCount > 0) {
	// PostPayList = defaultWapper.selectOrderPostPay(" * ", null,
	// " iOrderId in " + DataUtil.toInOfSql(orderIds));
	// }
	// defaultWapper.selectOrderPostPay(" top 1* ", null,
	// "1=1");
	// // 获取订单商品详情列表
	// if (rowsCount > 0) {
	// String queryField2 =
	// "oi.iOrderId , oi.sOrderInfoId , oi.fOriginalPrice , oi.iPriceType , oi.iAmount , oi.iBondedArea , oi.iCatalogStatus , oi.iCatalogType , oi.iProductSubCategoryId";
	// queryField2 +=
	// " , oi.iSailProtected , oi.iType , oi.sCatalogId , oi.sDescription , oi.sPictureUrl , oi.sProductId , oi.sPropertyInfo , oi.sReferenceUrl , oi.sSKU , oi.sTitle ";
	// queryField2 +=
	// " , e.sOrderInfoId as sOrderInfoExtId , e.bGiftAvail4Reward , e.iActivityId , e.iActivityTemplateId , oi.iSalesType";
	// queryField2 +=
	// " , oi.fProductPrice , oi.fProductOriginalPrice , oi.fSellerCouponAmount , oi.fYmtCouponAmount , oi.fDiscount , oi.fFreight";
	// queryField2 +=
	// " , oi.[fSellerPromotionAmount] , s.[PromotionId] , s.[PromotionType] , s.[PromotionName] , s.[MatchCondition] , s.[PromotionValue]";
	// queryField2 += " , s.ReducedAmount , oi.bSupportRtnWithoutReason";
	// String joinCondition2 =
	// " left join [dbo].[Ymt_OrderInfoExt] as e with(nolock) on oi.[sOrderInfoId] = e.[sOrderInfoId] ";
	// joinCondition2 +=
	// " left join [dbo].[Ymt_SellerPromotion] as s with(nolock) on oi.[iOrderId] = s.[OrderId] and oi.[sOrderInfoId] = s.[OrderInfoId]";
	// String queryCondition2 = " oi.iOrderId in "
	// + DataUtil.toInOfSql(orderIds);
	// OrderInfoList = defaultWapper.selectOrderInfo(queryField2,
	// joinCondition2, queryCondition2);
	// }
	//
	// // 获取订单物流信息
	// if (rowsCount > 0) {
	// OrderSummarieList = defaultWapper.selectOrderSummary2(
	// " [iOrderId], [iBillType], [sSummary]", null,
	// " iOrderId in " + DataUtil.toInOfSql(orderIds));
	// }
	//
	// // 获取订单冻结信息
	// if (rowsCount > 0) {
	// OrderFrozenList = defaultWapper.selectOrderFrozen(" * ", null,
	// " iOrderId in " + DataUtil.toInOfSql(orderIds));
	// }
	//
	// // 获取订单账单信息
	// if (rowsCount > 0) {
	// OrderToBillList = defaultWapper.selectOrderToBill(
	// " [iOrderid], [sBillId]",
	// null,
	// " [iAction]>=0 and iOrderId in "
	// + DataUtil.toInOfSql(orderIds));
	// OrderToBillList.forEach(x -> orderToBills.add(new OrderToBill(
	// (int) x.get("iOrderid"), DataUtil.Stringg
	// .getValueOrDefault(x.get("sBillId")))));
	//
	// }
	//
	// // 获取码头在线做单信息
	// List<String> billIds = new ArrayList<String>();
	// if (orderToBills.size() > 0) {
	// orderToBills.forEach(x -> billIds.add(x.getsBillId()));
	// BillList = defaultWapper.selectBill(
	// " * ",
	// null,
	// " [iAction] >= 0 and [sBillId] in "
	// + DataUtil.toInOfSql(billIds));
	// }
	//
	// // 订单有效的交易ID
	// if (rowsCount > 0) {
	// YmtTradingItemWapper ymtTradingItemWapper = new YmtTradingItemWapper();
	// List<Map> temp = ymtTradingItemWapper.selectTradingItem(
	// "[iOrderId], [iTradingId], [dUpdateTime]", null,
	// " iOrderId in " + DataUtil.toInOfSql(orderIds));
	// temp.forEach(x -> orderTradingIds.add(new OrderTradingId(
	// DataUtil.Integerr.GetValueOrDefault(x.get("iOrderId")),
	// DataUtil.Integerr.GetValueOrDefault(x.get("iTradingId")),
	// DataUtil.Stringg.getValueOrDefault(x.get("dUpdateTime")))));
	// // update virtaulTime from ymt_tradinginfo
	// List<Integer> iTradingIds = new ArrayList<Integer>();
	// orderTradingIds.forEach(x -> iTradingIds.add(x.getiTradingId()));
	// if (orderTradingIds.size() > 0) {
	// List<Map> temp2 = defaultWapper.selectTradingInfo("iTradingId",
	// null, "[iTradingStatus] = 2 and iTradingId in "
	// + DataUtil.toInOfSql(iTradingIds));
	// if (DataUtil.isNullOrEmpty(temp2) == false) {
	// for (Map m : temp2) {
	// int iTradingId = (int) m.get("iTradingId");
	// orderTradingIds.forEach(x -> {
	// if (x.getiTradingId() == iTradingId) {
	// x.setVirtualTime("9999-01-01 23:59:59");
	// }
	// });
	// }
	// }
	// orderTradingIds.sort((x, y) -> YMTDateUtil.parseDate(
	// y.getVirtualTime(), YMTDateUtil.YMDHMS).compareTo(
	// YMTDateUtil.parseDate(x.getVirtualTime(),
	// YMTDateUtil.YMDHMS)));
	// // OrderTradingId maxTid = orderTradingIds.get(0);
	// // TradingItemList = orderTradingIds
	// // .stream()
	// // .filter(x -> x.getiTradingId() == maxTid
	// // .getiTradingId()).collect(Collectors.toList());
	// TradingItemList = orderTradingIds;
	// }
	//
	// if (DataUtil.isNullOrEmpty(orderIds) == false) {
	// YmtOrderExtWapper ymtOrderExtMapper = new YmtOrderExtWapper();
	// OrderExtList = ymtOrderExtMapper
	// .selectOrderExt(
	// "[iOrderId], [bIsNeedUploadIdCard], [bHaveUploadedIdCard], [bNewSellerOrder], [bNewCustomerOrder]",
	// null,
	// "iOrderId in " + DataUtil.toInOfSql(orderIds));
	// }
	// }
	// return this;
	// }

	public Sp_GetSellerOrdersByOrderIds_v1 execute() {
		YmtOrdersWapper ymtOrdersWapper = new YmtOrdersWapper();

		List<Integer> orderIds = new ArrayList<Integer>();
		List<OrderToBill> orderToBills = new ArrayList<Sp_GetSellerOrdersByOrderIds_v1.OrderToBill>();
		List<OrderTradingId> orderTradingIds = new ArrayList<Sp_GetSellerOrdersByOrderIds_v1.OrderTradingId>();
		int rowsCount = 0;

		if (DataUtil.isNullOrEmpty(orderdt) == false) {
			orderIds.addAll(orderdt);
		}

		// 统计当前页订单数量
		rowsCount = orderIds.size();

		// 统计订单总量
		// totalCount = TotalCount;

		// 当页订单的详细信息
		if (false == DataUtil.isNullOrEmpty(orderIds)) {
			// String sql = "select t2.* ,u.snickname as [sBuyerNickName], "
			String sql = "select t2.iOrderId, t2.iUserId, t2.iBuyerId, t2.sMarkId, t2.dAddTime, t2.fOrderPrice, t2.fOrderDiscount, t2.fFreight, t2.fDiscount, t2.iTradingId, t2.iTradingStatus, t2.iOperate, t2.dOperateExpireTime, t2.sAddress, t2.sPostCode, t2.sReceivePerson, t2.sPhone, t2.sTelephone, t2.sQQ, t2.sEmail, t2.sLeaveWord, t2.iUnfreezeStatus, t2.dDispathTime, t2.iTopicId, t2.sTitle, t2.iReplyTopicWhenOrderPaid, t2.bPaidInFull, t2.fUseGiftAmount, t2.sCouponCode, t2.CouponValue, t2.iCouponType, t2.dPaidTime, t2.dApplyPostPayTime, t2.dPostPaidTime, t2.dConfirmedTime, t2.dChangeAddressTime, t2.iDistributor, t2.sThirdOrderId, t2.iType, t2.fOldFreight, t2.dDiscountTime, t2.fOldDiscount, t2.fAutoCancelOrderHours, t2.dCancelTime, t2.bShangouOrder, t2.sBuyerLoginId, t2.sBuyerLoginEmail, t2.sSellerLoginId, t2.sSellerLoginEmail, t2.iIsMerchant, t2.fTotalPrice, t2.fUseFreeCardAmount, t2.sHostRef, t2.bIncludeActivityProducts, t2.bShippedByXlobo, t2.dAcceptTime, t2.sCurType, t2.bCanLocalReturn, t2.bApplyLocalReturn, t2.dApplyLocalReturnTime, t2.iRiskVerifiedStatus, t2.dLastUpdateTime, t2.iThirdPartyRefundStatus, t2.iCouponChannel, t2.iSalesRefundStatus, t2.DataVersion, t2.bDomesticDelivered, t2.bEvaluated, t2.fOriginalPrice, t2.fPayableAmount, t2.fCommission, t2.sSellerCouponCode, t2.fSellerCouponAmount, t2.sYmtCouponCode, t2.fYmtCouponAmount, t2.iMainOrderId, t2.bFullPay, t2.fSellerPromotionAmount, t2.bDeleted, t2.bPreSale, t2.bCanEvaluate,"
							+ " u.snickname as [sBuyerNickName], "
							+ "	[realPay].* ,"
							+ "	[orderNote].*"
							+ " from [dbo].[Ymt_Orders] as t2 with(nolock)"
							+ " outer apply ("
							+ "	select"
							+ "		[realSettlementAmountOfCoupon] = sum(t3.[settlementAmountOfCoupon]),"
							+ "		[totalSalesRefundAmount] = sum(t3.[refundAmount]),"
							+ "		[totalRefundThirdPartyDiscount] = sum(isnull(t3.refundedDiscountOfThirdParty,0))"
							+ "	from [dbo].[Ymt_RefundBill] as t3 with(nolock) where t3.[OrderId] = t2.iOrderId AND t3.[SalesRefundStatus] = 10"
							+ " ) as [RealPay]"
							+ " outer apply ("
							+ "	select top 1 [note].[iRemarkLevel] , [remarkContent] = [note].[sContent]"
							+ "	from [dbo].[Ymt_O_OrderNote] as [note] with(nolock) "
							+ "	where [note].[iOrderId] = t2.[iOrderId] and [note].[iUserId] = t2.[iBuyerId]"
							+ ") as [orderNote]"
							+ " join ymt_users as u WITH(nolock) on u.iuserid = t2.iuserid"
							+ "  where [t2].[iOrderId] in"
							+ DataUtil.toInOfSql(orderIds)
							+ " order by t2.[iMainOrderId] desc ,t2.[iOrderId] asc, [t2].[sYmtCouponCode] desc option(recompile)";
			OrderList = new DefaultWapper().executeSql(sql);
			// 获取评价列表
			YmtCreditDetailWapper ymtCreditDetailWapper = new YmtCreditDetailWapper();
			CreditDetailList = ymtCreditDetailWapper.selectCreditDetail(" * ", null,
							" sTargetId in " + DataUtil.toInOfSql(orderIds));

			// 获取备注列表
			if (rowsCount > 0) {
				YmtOOrderNoteWapper ymtOOrderNoteWapper = new YmtOOrderNoteWapper();
				OrderNoteList = ymtOOrderNoteWapper.selectOrderNotes(" [iOrderId], [sContent] , [iRemarkLevel] ", null,
								" iUserId = " + sellerId + " and iOrderId in " + DataUtil.toInOfSql(orderIds));
			}
			// 获取订单金额详情列表
			DefaultWapper defaultWapper = new DefaultWapper();
			if (rowsCount > 0) {
				OrderStateList = defaultWapper.selectOrderStatesByOrderIds(" * ", null,
								" iOrderId in " + DataUtil.toInOfSql(orderIds));
			}
			// 获取订单补款列表
			if (rowsCount > 0) {
				PostPayList = defaultWapper.selectOrderPostPay(" * ", null,
								" iOrderId in " + DataUtil.toInOfSql(orderIds));
			}
			defaultWapper.selectOrderPostPay(" top 1* ", null, "1=1");
			// 获取订单商品详情列表
			if (rowsCount > 0) {
				String queryField2 = "oi.iOrderId , oi.bPspProduct, oi.sOrderInfoId , oi.fOriginalPrice , oi.iPriceType , oi.iAmount , oi.iBondedArea , oi.iCatalogStatus , oi.iCatalogType , oi.iProductSubCategoryId";
				queryField2 += " , oi.iSailProtected , oi.iType , oi.sCatalogId , oi.sDescription , oi.sPictureUrl , oi.sProductId , oi.sPropertyInfo , oi.sReferenceUrl , oi.sSKU , oi.sTitle ";
				queryField2 += " , e.sOrderInfoId as sOrderInfoExtId , e.bGiftAvail4Reward , e.iActivityId , e.iActivityTemplateId , oi.iSalesType";
				queryField2 += " , oi.fProductPrice , oi.fProductOriginalPrice , oi.fSellerCouponAmount , oi.fYmtCouponAmount , oi.fDiscount , oi.fFreight";
				queryField2 += " , oi.[fSellerPromotionAmount] , s.[promotionId] , s.[promotionType] , s.[promotionName] , s.[matchCondition] , s.[promotionValue]";
				queryField2 += " , s.reducedAmount , oi.bSupportRtnWithoutReason";
				String joinCondition2 = " left join [dbo].[Ymt_OrderInfoExt] as e with(nolock) on oi.[sOrderInfoId] = e.[sOrderInfoId] ";
				joinCondition2 += " left join [dbo].[Ymt_SellerPromotion] as s with(nolock) on oi.[iOrderId] = s.[orderId] and oi.[sOrderInfoId] = s.[orderInfoId]";
				String queryCondition2 = " oi.iOrderId in " + DataUtil.toInOfSql(orderIds);
				OrderInfoList = defaultWapper.selectOrderInfo(queryField2, joinCondition2, queryCondition2);
			}

			// 获取订单物流信息
			if (rowsCount > 0) {
				OrderSummarieList = defaultWapper.selectOrderSummary2(" [iOrderId], [iBillType], [sSummary]", null,
								" iOrderId in " + DataUtil.toInOfSql(orderIds));
			}

			// 获取订单冻结信息
			if (rowsCount > 0) {
				OrderFrozenList = defaultWapper.selectOrderFrozen(" * ", null,
								" iOrderId in " + DataUtil.toInOfSql(orderIds));
			}

			// 获取订单账单信息
			if (rowsCount > 0) {
				OrderToBillList = defaultWapper.selectOrderToBill(" [iOrderid], [sBillId]", null,
								" [iAction]>=0 and iOrderId in " + DataUtil.toInOfSql(orderIds));
				OrderToBillList.forEach(x -> orderToBills.add(new OrderToBill((int) x.get("iOrderid"), DataUtil.Stringg
								.getValueOrDefault(x.get("sBillId")))));

			}

			// 获取码头在线做单信息
			List<String> billIds = new ArrayList<String>();
			if (orderToBills.size() > 0) {
				orderToBills.forEach(x -> billIds.add(x.getsBillId()));
				BillList = defaultWapper.selectBill(" * ", null,
								" [iAction] >= 0 and [sBillId] in " + DataUtil.toInOfSql(billIds));
			}

			// 订单有效的交易ID
			if (rowsCount > 0) {
				YmtTradingItemWapper ymtTradingItemWapper = new YmtTradingItemWapper();
				List<Map> temp = ymtTradingItemWapper.selectTradingItem("[iOrderId], [iTradingId], [dUpdateTime]",
								null, " iOrderId in " + DataUtil.toInOfSql(orderIds));
				temp.forEach(x -> orderTradingIds.add(new OrderTradingId(DataUtil.Integerr.GetValueOrDefault(x
								.get("iOrderId")), DataUtil.Integerr.GetValueOrDefault(x.get("iTradingId")),
								DataUtil.Stringg.getValueOrDefault(x.get("dUpdateTime")))));
				// update virtaulTime from ymt_tradinginfo
				List<Integer> iTradingIds = new ArrayList<Integer>();
				orderTradingIds.forEach(x -> iTradingIds.add(x.getiTradingId()));
				if (orderTradingIds.size() > 0) {
					List<Map> temp2 = defaultWapper.selectTradingInfo("iTradingId", null,
									"[iTradingStatus] = 2 and iTradingId in " + DataUtil.toInOfSql(iTradingIds));
					if (DataUtil.isNullOrEmpty(temp2) == false) {
						for (Map m : temp2) {
							int iTradingId = (int) m.get("iTradingId");
							orderTradingIds.forEach(x -> {
								if (x.getiTradingId() == iTradingId) {
									x.setVirtualTime("9999-01-01 23:59:59");
								}
							});
						}
					}
					orderTradingIds.sort((x, y) -> YMTDateUtil.parseDate(y.getVirtualTime(), YMTDateUtil.YMDHMS)
									.compareTo(YMTDateUtil.parseDate(x.getVirtualTime(), YMTDateUtil.YMDHMS)));
					// OrderTradingId maxTid = orderTradingIds.get(0);
					// TradingItemList = orderTradingIds
					// .stream()
					// .filter(x -> x.getiTradingId() == maxTid
					// .getiTradingId()).collect(Collectors.toList());
					TradingItemList = orderTradingIds;
				}

				if (DataUtil.isNullOrEmpty(orderIds) == false) {
					YmtOrderExtWapper ymtOrderExtMapper = new YmtOrderExtWapper();
					OrderExtList = ymtOrderExtMapper
									.selectOrderExt("[iOrderId], [bIsNeedUploadIdCard], [bHaveUploadedIdCard], [bNewSellerOrder], [bNewCustomerOrder], [sOrderSource]",
													null, "iOrderId in " + DataUtil.toInOfSql(orderIds));
				}
			}
		}
		return this;
	}

	private List<Map> OrderList = new ArrayList<Map>();
	private List<Map> CreditDetailList = new ArrayList<Map>();
	private List<Map> OrderNoteList = new ArrayList<Map>();
	private List<Map> OrderStateList = new ArrayList<Map>();
	private List<Map> PostPayList = new ArrayList<Map>();
	private List<Map> OrderInfoList = new ArrayList<Map>();
	private List<Map> OrderSummarieList = new ArrayList<Map>();
	private List<Map> OrderFrozenList = new ArrayList<Map>();
	private List<Map> OrderToBillList = new ArrayList<Map>();
	private List<Map> BillList = new ArrayList<Map>();
	private List<OrderTradingId> TradingItemList = new ArrayList<OrderTradingId>();
	private List<Map> OrderExtList = new ArrayList<Map>();

	public List<Map> getOrderStateList() {
		return OrderStateList;
	}

	public List<Map> getOrderList() {
		return OrderList;
	}

	public List<Map> getCreditDetailList() {
		return CreditDetailList;
	}

	public List<Map> getOrderNoteList() {
		return OrderNoteList;
	}

	public List<Map> getPostPayList() {
		return PostPayList;
	}

	public List<Map> getOrderInfoList() {
		return OrderInfoList;
	}

	public List<Map> getOrderSummarieList() {
		return OrderSummarieList;
	}

	public List<Map> getOrderFrozenList() {
		return OrderFrozenList;
	}

	public List<Map> getOrderToBillList() {
		return OrderToBillList;
	}

	public List<Map> getBillList() {
		return BillList;
	}

	public List<OrderTradingId> getTradingItemList() {
		return TradingItemList;
	}

	public List<Map> getOrderExtList() {
		return OrderExtList;
	}

}
